package cn.tj212.xiaoyin.core.course.domain;

import cn.tj212.xiaoyin.common.util.BeanUtil;
import org.apache.commons.lang.StringUtils;

public class CourseQueryDto extends Course {

    private String sortField;

    private String sortDerection="DESC";

    private Integer start=0;//limit开始

    private Integer count;//偏移量

    private Integer end;//limit结束

    /**
     * 按照sortField升序
     * @param sortField sortField是java bean的属性
     */
    public void ascSortField(String sortField){
        if (StringUtils.isNotEmpty(sortField)){
            this.sortField=BeanUtil.fieldToColumn(sortField);
            this.sortDerection="ASC";
        }
    }

    /**
     * 按照sortField降序
     * @param sortField
     */
    public void descSortField(String sortField){
        if (StringUtils.isNotEmpty(sortField)){
            this.sortField=BeanUtil.fieldToColumn(sortField);
            this.sortDerection="DESC";
        }
    }

    public String getSortField() {
        return sortField;
    }

    public void setSortField(String sortField) {
        this.sortField = sortField;
    }

    public String getSortDerection() {
        return sortDerection;
    }

    public void setSortDerection(String sortDerection) {
        this.sortDerection = sortDerection;
    }

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getEnd() {
        if(null!=this.count){
            if (null==this.start){
                this.start=0;
            }
            this.end=this.start+this.count;
        }
        return end;
    }

}
